class Db {
  constructor() {
    console.log('实例化对象触发构造函数');
    this.connect();
  }
  connect() {
    console.log('连接数据库成功');
  }
  find() {
    console.log('查找数据');
  }
  static getInstance() {  //单例，多次实例化只会触发构造器一次
    if(!Db.instance) {
      Db.instance = new Db();
    }
    return Db.instance;
  }
}

var db1 = Db.getInstance()

var db2 = Db.getInstance()

var db3 = Db.getInstance()

var db4 = Db.getInstance()